package com.frxuexi.mine.viewmodel

import com.frxuexi.lib_base.BaseViewModel
import com.frxuexi.lib_base.entity.BaseEntity
import com.frxuexi.mine.intent.LeaveIntent
import com.frxuexi.mine.intent.UserIntent
import com.frxuexi.mine.repository.LeaveRepository
import com.frxuexi.mine.repository.UserRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@HiltViewModel
class LeaveViewModel @Inject constructor(private val leaveRepository: LeaveRepository):BaseViewModel<LeaveIntent>() {
    override fun handleIntent(it: LeaveIntent) {
        when(it){
            is LeaveIntent.addLeave->{
                httpRequest2(leaveRepository.addLeave(it.map))
            }
            is LeaveIntent.getLeaves->{
                httpRequest2(leaveRepository.getLeaves(it.status) as Flow<BaseEntity<Any>>)
            }
            is LeaveIntent.comLeave->{
                httpRequest2(leaveRepository.comLeave(it.map))
            }
        }
    }
}